using UnityEngine;

[ExecuteInEditMode]
public class editsteppos : MonoBehaviour
{
	public DataController alldata;

	public bool isrunflag;

	public int stepid;

	private PosRot tempposrot;

	private int curstep;

	private void Update()
	{
		if (isrunflag)
		{
			alldata = GameObject.Find("DataController").GetComponent<DataController>();
			base.transform.name = "step" + stepid;
			readinfo();
			isrunflag = false;
		}
	}

	public void readinfo()
	{
		for (int i = 0; i < alldata.DataStep.Count; i++)
		{
			if (alldata.DataStep[i].ID == stepid)
			{
				curstep = i;
				break;
			}
		}
		foreach (Transform item in base.transform)
		{
			switch (item.name)
			{
			case "despos":
				foreach (Transform item2 in item)
				{
					alldata.DataStep[curstep].despos = item2.transform.position;
				}
				break;
			case "enemy1":
				addpos(isenemy: true, 0, item);
				break;
			case "enemy2":
				addpos(isenemy: true, 1, item);
				break;
			case "enemy3":
				addpos(isenemy: true, 2, item);
				break;
			case "enemy4":
				addpos(isenemy: true, 3, item);
				break;
			case "enemy5":
				addpos(isenemy: true, 4, item);
				break;
			case "enemy6":
				addpos(isenemy: true, 5, item);
				break;
			case "fri1":
				addpos(isenemy: false, 0, item);
				break;
			case "fri2":
				addpos(isenemy: false, 1, item);
				break;
			case "fri3":
				addpos(isenemy: false, 2, item);
				break;
			case "fri4":
				addpos(isenemy: false, 3, item);
				break;
			case "fri5":
				addpos(isenemy: false, 4, item);
				break;
			case "fri6":
				addpos(isenemy: false, 5, item);
				break;
			}
		}
		UnityEngine.Debug.Log("READ OVER!!!  " + stepid + "  : step");
	}

	public void addpos(bool isenemy, int ind, Transform par)
	{
		if (isenemy)
		{
			if (ind < alldata.DataStep[curstep].enemy_id_num.Count)
			{
				alldata.DataStep[curstep].enemy_id_num[ind].pos_rot.Clear();
				foreach (Transform item in par)
				{
					tempposrot = null;
					tempposrot = new PosRot();
					tempposrot.pos = item.position;
					tempposrot.rot = item.eulerAngles;
					alldata.DataStep[curstep].enemy_id_num[ind].pos_rot.Add(tempposrot);
				}
			}
		}
		else if (ind < alldata.DataStep[curstep].fri_id_num.Count)
		{
			alldata.DataStep[curstep].fri_id_num[ind].pos_rot.Clear();
			foreach (Transform item2 in par)
			{
				tempposrot = null;
				tempposrot = new PosRot();
				tempposrot.pos = item2.position;
				tempposrot.rot = item2.eulerAngles;
				alldata.DataStep[curstep].fri_id_num[ind].pos_rot.Add(tempposrot);
			}
		}
	}
}
